package com.winning.ds.common.util;

import com.winning.ds.common.util.freemarker.FreemarkerConfiguration;
import freemarker.template.Configuration;
import freemarker.template.Template;

import java.io.BufferedWriter;
import java.io.StringWriter;
import java.util.Map;

public class HtmlGenerator {


	/**
	 * @Author: nxs@winning.com.cn
	 *
	 * @Description: 装配模板 
	 *
	 * @Date:  2018-04-11 17:30:38
	 *
	 * @Param: [template, variables]
	 *
	 * @return: java.lang.String
	 *
	 **/
	public static String generate(String template, Map<String, Object> variables)
			throws Exception {
		Configuration config = FreemarkerConfiguration.getConfiguation();
		config.setDefaultEncoding("UTF-8");
		Template tp = config.getTemplate(template);
		StringWriter stringWriter = new StringWriter();
		BufferedWriter writer = new BufferedWriter(stringWriter);
		tp.setEncoding("UTF-8");
		tp.process(variables, writer);
		String htmlStr = stringWriter.toString();
		writer.flush();
		writer.close();
		return htmlStr;

	}
}
